#include <iostream>
#include<string>
#include<map>
#include<vector>
using namespace std;
map<string,int> order;
vector<int> num1;
vector<int> num2;
string s1,s2;
void print(string & i)
{
    for(auto t :i)
    {
        cout << t << ' ';
    }
}
bool judge_jj()
{

    if(s1 == "joker JOKER" || s2 == "joker JOKER")
    {
        return true;
    }
    return false;
}
void change()
{
    string tem;
    int j = 0;
    if(order.count(s1))
    {
        j++;
        num1.push_back(order[s1]);
    }
    if(order.count(s2))
    {
        j++;
        num1.push_back(order[s1]);

        
    }
    if(j == 2) return;


    for(int i = 0;i < s1.size();i++)
    {
        if(!(s1[i] == ' '))
        {
            tem.clear();
            tem += s1[i];
        }
        else {
           num1.push_back(order[tem]);
            
        }

    }
     for(int i = 0;i < s1.size();i++)
    {
        if(!(s2[i] == ' '))
        {
            tem.clear();
            tem += s2[i];
        }
        else {
           num2.push_back(order[tem]);
            
        }

    }
}
void init()
{
    order["JOKER"] = 1;
    order["joker"] = 2;
    order["2"] = 3;
    order["A"] = 4;
    order["K"] = 5;
    order["Q"] = 6;
    order["J"] = 7;
    order["10"] = 8;
    order["9"] = 9;
    order["8"] = 10;
    order["7"] = 11;
    order["6"] = 12;
    order["5"] = 13;
    order["4"] = 14;
    order["3"] = 15;
}
bool judge_bome(vector<int>& arr)
{
    if(arr.size() < 4) return false;
    for(int i  =0;i < arr.size() - 1;i++)
    {
        if(arr[i] - arr[i + 1])
        {
           return false; 
        }
    }
    return true;
}
void s_cmp()
{
    if(num1[0] < num2[0])
    {
        cout  << s1;
    }
    else {
        
        cout  << s2;

    }
}

int main() {
    string sum;
    getline(cin,sum);
    
    bool flag = false;
    bool jud1 = false;
    bool jud2 = false;

    for(auto i : sum)
    {
        if(i == '-')
        {
            flag = true;
            continue;
        }
        if(i=='0' && !flag)
        {
            jud1 = true;
        }
        else if(i == '0' && flag)
        {
            jud2 = true;
        }
        if(!flag)
        {
            s1 += i;
        }
        if(flag)
        {
            s2 += i;
        }
    }
    
    if(judge_jj()) 
    {
        cout << "joker JOKER" << endl;
        return 0;
    }

    init();
    change();
    int sz1 = num1.size();
    int sz2 = num2.size();
    s1 += ' ';
    s2 += ' ';
    if(sz1 == sz2)
    {
    
        switch(sz1)
        {
            case 1:
                s_cmp();
                break;
            case 3:
                s_cmp();
            break;
            case 7:
                s_cmp();
                break;
            case 9:
                s_cmp();
            break;
        }
    }
    else
    {
        if(judge_bome(num1))
        {
            cout << s1;
            return 0;
        }
        else if(judge_bome(num2))
        {
            cout << s2;
            return 0;
        }
        cout << "ERROR" << endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")